﻿@page "/"
@page "/search/{searchText}/{page:int}"
@page "/{categoryUrl}"

@inject IProductService _productService

<PageTitle>Joker Shop</PageTitle>

@if (SearchText == null && CategoryUrl == null)
{
    <FeaturedProducts />
}
else
{
    <ProductList />
}



@code {
    [Parameter]
    public string? CategoryUrl { get; set; } = null;

    [Parameter]
    public string? SearchText { get; set; } = null;

    [Parameter]
    public int Page { get; set; } = 1;

    protected override async Task OnParametersSetAsync()
    {
        if (SearchText != null)
        {
            await _productService.SearchProducts(SearchText,Page);
        }
        else
        {
            await _productService.GetProducts(CategoryUrl);
        }
    }


}

